﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace WebApplication1.Page
{
    public partial class UserManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MembershipUser User = Membership.GetUser();
            string[] roles=Roles.GetRolesForUser();
            foreach (string str in roles)
            {
                if (str == "系统管理员")
                {
                    string[] zx = Roles.GetUsersInRole("中心管理员");
                    string[] fj = Roles.GetUsersInRole("分局管理员");
                    string[] yh = Roles.GetUsersInRole("普通用户");
                    string[] xt=null;
                    if (Roles.IsUserInRole("系统管理员_修改") || Roles.IsUserInRole("系统管理员_删除"))
                    {
                        xt = Roles.GetUsersInRole("系统管理员");                        
                    }         
                    int l=zx.Length+fj.Length+yh.Length;
                    if (xt != null)
                        l += xt.Length;
                    string[] data = new string[l];
                    l = 0;
                    if(xt!=null)
                    {
                        for (int i = 0; i < xt.Length; i++)
                        {
                            data[l++] = xt[i];
                        }
                    }
                    for (int i = 0; i < zx.Length; i++)
                    {
                        data[l++] = zx[i];
                    }
                    for (int i = 0; i < fj.Length; i++)
                    {
                        data[l++] = fj[i];
                    }
                    for (int i = 0; i < yh.Length; i++)
                    {
                        data[l++] = yh[i];
                    }
                    GridView1.DataSource = Membership.GetAllUsers();
                    GridView1.DataBind();
                }
                else if (str == "中心管理员")
                {
                    GridView1.DataSource = Roles.GetUsersInRole("分局管理员");
                }
                else if (str == "系统管理员")
                {
                }
                else
                {

                }
            }
        }
        protected void GridView1_DataBound(object sender, EventArgs e)
        {

        }
        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
//             if (e.Row.RowType == DataControlRowType.Pager)
//                 WFWebLib.GridViewOperation.GridRowCreated(sender, e);
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            //BindDisplayList(e.NewPageIndex);
        }
        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
//             LinkButton UserNameLinkButton = (LinkButton)GridView1.Rows[e.NewSelectedIndex].FindControl("UserNameLinkButton");
//             DetailsView1.ChangeMode(DetailsViewMode.ReadOnly);
//             BindDetailsView(UserNameLinkButton.Text);
//             DetailsViewUadatePanel.Update();
//             ItemEditorModalPopupExtender.Show();
        }
    }
}